package com.study.d13_tcp_bs;

import java.io.OutputStream;
import java.io.PrintStream;
import java.net.Socket;

public class ServerReaderThread extends Thread{
    private Socket socket;
    public ServerReaderThread(Socket socket){
        this.socket=socket;
    }

    @Override
    public void run() {
        //立马响应一个网页内容：“黑马程序员”给浏览器展示

        try {
            OutputStream outputStream = socket.getOutputStream();
//            DataOutputStream dos = new DataOutputStream(outputStream);
//            dos.writeUTF("黑马程序员");
            //注意！：服务器必须给浏览器相应HTTP协议规定的数据形式
            //否则浏览器不识别返回的数据
            PrintStream ps = new PrintStream(outputStream);
            ps.println("HTTP/1.1 200 OK");
            ps.println("Content-type:text/html;charset=UTF-8");
            ps.println();//必须换行
            ps.println("<div style='color:red;font-size:120px;text-align:center'>黑马程序员</div>");
            ps.close();
            socket.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
